package com.cssw.fyzb.wap.controller;

import com.cssw.fyzb.base.web.context.UserContext;
import com.cssw.fyzb.base.web.domain.AjaxData;
import com.cssw.fyzb.base.web.domain.AjaxPage;
import com.cssw.fyzb.wap.model.dto.*;
import com.cssw.fyzb.wap.model.vo.*;
import com.cssw.fyzb.wap.service.LiveService;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author wondream
 */
@RestController
@RequestMapping("/live")
public class LiveController {

    @Autowired
    LiveService liveService;

    @ApiOperation("踢人")
    @ApiImplicitParam(name = "dto", value = "踢人", dataType = "AddLiveKickOutDto")
    @PostMapping("addLiveKickOut")
    public AjaxData addLiveKickOut(@RequestBody AddLiveKickOutDto dto) {
        return liveService.addLiveKickOut(UserContext.getUserId(), dto.getLiveId(), dto.getUserId());
    }

    @ApiOperation("禁言")
    @ApiImplicitParam(name = "dto", value = "禁言", dataType = "AddLiveMuteDto")
    @PostMapping("addLiveMute")
    public AjaxData addLiveMute(@RequestBody AddLiveMuteDto dto) {
        return liveService.addLiveMute(dto.getLiveId(), UserContext.getUserId(), dto.getUserId());
    }

    @ApiOperation("取消踢人")
    @ApiImplicitParam(name = "dto", value = "取消踢人", dataType = "DeleteByIdDto")
    @PostMapping("removeLiveKickOut")
    public AjaxData removeLiveKickOut(@RequestBody DeleteByIdDto dto) {
        return liveService.removeLiveKickOut(dto.getId());
    }

    @ApiOperation("取消禁言")
    @ApiImplicitParam(name = "dto", value = "取消禁言", dataType = "DeleteByIdDto")
    @PostMapping("removeLiveMute")
    public AjaxData removeLiveMute(@RequestBody DeleteByIdDto dto) {
        return liveService.removeLiveMute(dto.getId());
    }

    @ApiOperation("踢人列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "liveId", value = "直播标识", paramType = "query", dataType = "int", required = true),
            @ApiImplicitParam(name = "pageNumber", value = "页码, 从0开始", paramType = "query", dataType = "int", required = true),
            @ApiImplicitParam(name = "pageSize", value = "页大小", paramType = "query", dataType = "int", required = true),

    })
    @GetMapping("listLiveKickOut")
    public AjaxPage<LiveKickOutVo> listLiveKickOut(Long liveId, Integer pageNumber, Integer pageSize) {
        return liveService.listLiveKickOut(liveId, pageNumber, pageSize);
    }

    @ApiOperation("禁言列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "liveId", value = "直播标识", paramType = "query", dataType = "int", required = true),
            @ApiImplicitParam(name = "pageNumber", value = "页码, 从0开始", paramType = "query", dataType = "int", required = true),
            @ApiImplicitParam(name = "pageSize", value = "页大小", paramType = "query", dataType = "int", required = true),
    })
    @GetMapping("listLiveMute")
    public AjaxPage<LiveMuteVo> listLiveMute(Long liveId, Integer pageNumber, Integer pageSize) {
        return liveService.listLiveMute(liveId, pageNumber, pageSize);
    }

    @ApiOperation("开启直播-创建房间")
    @ApiImplicitParam(name = "dto", value = "开启直播-创建房间", dataType = "CreateLiveRoomDto")
    @PostMapping("createLiveRoom")
    public AjaxData<LiveRoomVo> createLiveRoom(@RequestBody CreateLiveRoomDto dto) {
        return liveService.createLiveRoom(UserContext.getUserId(), dto.getTitle(), dto.getThumb(), dto.getLat(), dto.getLng());
    }

    @ApiOperation("关闭直播-退出房间")
    @ApiImplicitParam(name = "dto", value = "关闭直播-退出房间", dataType = "DropLiveRoomDto")
    @PostMapping("dropLiveRoom")
    public AjaxData<LiveRoomVo> dropLiveRoom(@RequestBody DropLiveRoomDto dto) {
        return liveService.dropLiveRoom(UserContext.getUserId(), dto.getLiveId());
    }

    @ApiOperation("查询观众列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "liveId", value = "直播标识", paramType = "query", dataType = "string", required = true),
            @ApiImplicitParam(name = "num", value = "查询数量", paramType = "query", dataType = "string", required = false),
    })
    @GetMapping("listAudience")
    public AjaxPage<AudienceVo> listAudience(Long liveId, Integer num) {
        return liveService.listAudience(UserContext.getUserId(), liveId, num);
    }

    @ApiOperation("主播查询观众列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "liveId", value = "直播标识", paramType = "query", dataType = "string", required = true)
    })
    @GetMapping("listAudienceByAnchor")
    public AjaxPage<AudienceVo> listAudienceByAnchor(Long liveId) {
        return liveService.listAudienceByAnchor(UserContext.getUserId(), liveId);
    }

    @ApiOperation("进入直播间")
    @ApiImplicitParam(name = "dto", value = "进入直播间", dataType = "EnterLiveRoomDto")
    @PostMapping("enterLiveRoom")
    public AjaxData<EnterLiveRoomVo> enterLiveRoom(@RequestBody EnterLiveRoomDto dto) {
        return liveService.enterLiveRoom(UserContext.getUserId(), dto.getLiveId());
    }

    @ApiOperation("退出直播间")
    @ApiImplicitParam(name = "dto", value = "退出直播间", dataType = "ExitLiveRoomDto")
    @PostMapping("exitLiveRoom")
    public AjaxData exitLiveRoom(@RequestBody ExitLiveRoomDto dto) {
        return liveService.exitLiveRoom(UserContext.getUserId(), dto.getLiveId());
    }

    @ApiOperation("点赞")
    @ApiImplicitParam(name = "dto", value = "点赞", dataType = "LiveLikesDto")
    @PostMapping("liveLikes")
    public AjaxData liveLikes(@RequestBody LiveLikesDto dto) {
        return liveService.liveLikes(UserContext.getUserId(), dto.getLiveId());
    }

    @ApiOperation("举报")
    @ApiImplicitParam(name = "dto", value = "举报", dataType = "AddLiveReportDto")
    @PostMapping("addLiveReport")
    public AjaxData addLiveReport(@RequestBody AddLiveReportDto dto) {
        return liveService.addLiveReport(dto.getLiveId(), UserContext.getUserId(), dto.getToUserId(), dto.getContent());
    }

    @ApiOperation("创建混流")
    @ApiImplicitParam(name = "dto", value = "创建混流", dataType = "CreateMixLiveStreamDto")
    @PostMapping("createMixLiveStream")
    public AjaxData createMixLiveStream(@RequestBody CreateMixLiveStreamDto dto) {
        return liveService.createMixLiveStream(dto.getLiveId(), dto.getParams());
    }

    @ApiOperation("取消混流")
    @ApiImplicitParam(name = "dto", value = "创建混流", dataType = "CancelMixLiveStreamDto")
    @PostMapping("cancelMixLiveStream")
    public AjaxData cancelMixLiveStream(@RequestBody CancelMixLiveStreamDto dto) {
        return liveService.cancelMixLiveStream(dto.getLiveId());
    }

    @ApiOperation("搜索直播")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "key", value = "关键字", paramType = "query", dataType = "int", required = true),
            @ApiImplicitParam(name = "pageNumber", value = "页码, 从1开始", paramType = "query", dataType = "int", required = true),
            @ApiImplicitParam(name = "pageSize", value = "页大小", paramType = "query", dataType = "int", required = true),

    })
    @GetMapping("searchLive")
    public AjaxPage<LiveVo> searchLive(String key, Integer pageNumber, Integer pageSize) {
        return liveService.searchLive(UserContext.getUserId(), key, pageNumber, pageSize);
    }

    @ApiOperation("获取直播统计（结束直播后查询）")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "liveId", value = "直播间标识", paramType = "query", dataType = "int", required = true)
    })
    @GetMapping("getLiveStat")
    public AjaxData<LiveStatVo> getLiveStat(Long liveId) {
        return liveService.getLiveStat(UserContext.getUserId(), liveId);
    }

    @ApiOperation("查询直播间礼物统计")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "liveId", value = "直播间标识", paramType = "query", dataType = "int", required = true)
    })
    @GetMapping("listLiveGiftCount")
    public AjaxPage<LiveGiftCountVo> listLiveGiftCount(Long liveId) {
        return liveService.listLiveGiftCount(UserContext.getUserId(), liveId);
    }

    @ApiOperation("添加视频")
    @GetMapping("getVideoUploadSig")
    public AjaxData<UploadSigVo> getVideoUploadSig() {
        return liveService.getVideoUploadSig();
    }

}
